home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / exportComposerCurves.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  7.8 KB  |  328 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:       23 July 1998
  22. //  Procedure Name:      exportComposerCurves
  23. //  Description: 
  24. //
  25. //<doc>
  26. //<name exportComposerCurves>
  27. //<owner "Alias|Wavefront Unsupported">
  28. //
  29. //<synopsis>
  30. //        exportComposerCurves
  31. //
  32. //<description>
  33. //    Generates a bezier curve(s) to import into Composer
  34. //    based on a specified attribute in Maya.        
  35. //<ol>
  36. //    <li>Select objects with attributes to be exported
  37. //    <li>exportComposerCurves
  38. //    <li>select which attributes should be exported
  39. //</ol>
  40. //    This will output a ".cmp" to the current maya project's
  41. //    directory. You can File>Import this into Composer.
  42. //<flags>
  43. //    none
  44. //
  45. //<returns>
  46. //      none
  47. //
  48. //<examples>
  49. //  select -r nurbsSphere1;
  50. //  exportComposerCurves;
  51. //</doc>
  52. //
  53.  
  54.  
  55. global proc tvcCurve (string $attrName, int $choice)
  56. {
  57.  
  58.     // temp holder of current attribute value
  59.  
  60.     float $tmpVal;
  61.     global string $name;
  62.  
  63.     // get names of text input fields
  64.  
  65.     $cmpname = `textFieldGrp -q -tx $name`;
  66.  
  67.     // Set up output filename to projects directory
  68.  
  69.     string $workspace = `workspace -q -rd`;
  70.     $filename = ( $workspace + "/" + $cmpname );
  71.  
  72.     // open filename for printing
  73.  
  74.     if ($choice == 0)
  75.     {
  76.     int $fileId = fopen( $filename, "w" );
  77.     fprint ($fileId, "#! Composer Bezier Curves Created in Maya \n");
  78.     fclose( $fileId );
  79.     }
  80.  
  81.  
  82.     //
  83.     //  Only output curves with at least two keyframes
  84.     //
  85.  
  86.     $n_keyframes = `keyframe -q -keyframeCount $attrName`;
  87.  
  88.     if ( $n_keyframes > 1 )
  89.     {
  90.     // open file again for appending
  91.  
  92.     int $fileId = fopen( $filename, "a" );
  93.     fprint ($fileId, "#! " + $attrName + "\n");
  94.  
  95.     //
  96.     // select the curve and turn on weighted tangents
  97.     //
  98.  
  99.     selectKey -clear;
  100.     selectKey -add -k $attrName;
  101.     int $wt[] = `keyTangent -q -weightedTangents`;
  102.     keyTangent -e -weightedTangents true;
  103.  
  104.     // this is the first part of the CardinalCurve definition
  105.     // first break up the file name to get rid of the decimal
  106.     // and any posible pipe symbols since Composer doesnt like them
  107.  
  108.     string $tmp = `substitute "|" $attrName "_"`;
  109.     string $noPipeName = `substitute "\\." $tmp "_"`;
  110.     fprint ($fileId, $noPipeName + " = Bezier(");
  111.  
  112.     // get the attr value and print it to the filename
  113.  
  114.     float $t[] = `keyframe -q $attrName`;
  115.     float $v[] = `keyframe -q -vc $attrName`;
  116.     float $inA[] = `keyTangent -q -inAngle $attrName`;
  117.     float $outA[] = `keyTangent -q -outAngle $attrName`;
  118.     float $inW[] = `keyTangent -q -inWeight $attrName`;
  119.     float $outW[] = `keyTangent -q -outWeight $attrName`;
  120.  
  121.     for ($i = 0; $i < $n_keyframes; ++$i )
  122.     {
  123.         fprint ($fileId, $v[$i] + "@" + trunc($t[$i]) + "," );
  124.         if ($i%4==0)
  125.         {
  126.         fprint ($fileId, "\n\t");        
  127.         }
  128.     }
  129.  
  130.  
  131.     //
  132.     //  This is the bezier identifier
  133.     //
  134.  
  135.     fprint ($fileId, "50");
  136.  
  137.  
  138.     //
  139.     //  Now write the tangents
  140.     //
  141.  
  142.     for ($i = 0; $i < $n_keyframes; ++$i )
  143.     {
  144.         float $tangent[4];
  145.  
  146.         $tangent[0] = -cos(deg_to_rad($inA[$i])) * $inW[$i];
  147.         $tangent[1] = -sin(deg_to_rad($inA[$i])) * $inW[$i];
  148.         $tangent[2] = cos(deg_to_rad($outA[$i])) * $outW[$i];
  149.         $tangent[3] = sin(deg_to_rad($outA[$i])) * $outW[$i];
  150.  
  151.         fprint($fileId, ",[" + $tangent[0] + "," + $tangent[1] + ","
  152.             + $tangent[2] + "," + $tangent[3] + "]");
  153.         if ($i%4==0)
  154.         {
  155.         fprint ($fileId, "\n\t");        
  156.         }
  157.     }
  158.  
  159.  
  160.     //
  161.     //  We are done
  162.     //
  163.  
  164.  
  165.     keyTangent -e -weightedTangents $wt[0];
  166.     fprint ($fileId, ")\n");
  167.     fclose( $fileId );
  168.  
  169.     // send message to script ed
  170.     print ("// Result: Outputing " + $attrName + " to " + $filename + "\n");
  171.     }
  172.  
  173. }   // end tvcCurve()
  174.  
  175.  
  176. global proc getExportAttr(string $objList, int $choice)
  177. {
  178.     string $objList;
  179.     int $choice;
  180.     string $exportAttr[];
  181.  
  182.     // $choice to determine to export selected or all
  183.  
  184.     if ($choice == 0)
  185.     {
  186.     $exportAttr = `textScrollList -q -si $objList`;
  187.     }
  188.     else
  189.     {
  190.     $exportAttr = `textScrollList -q -ai $objList`;
  191.     }
  192.  
  193.     if (size($exportAttr)>0)
  194.     {
  195.     for ($x = 0; $x < size($exportAttr); $x++)
  196.     {
  197.         if ($x==0)
  198.         {
  199.         tvcCurve $exportAttr[$x] 0;
  200.         }
  201.         else
  202.         {
  203.         tvcCurve $exportAttr[$x] 1;
  204.         }
  205.     }  
  206.     } 
  207.     else
  208.     {
  209.     error ("Export Failed. Nothing was selected.");
  210.     }
  211.  
  212. }  // end getExportAttr()
  213.  
  214.  
  215. global proc updateSelected()
  216. {
  217.     string $selList[] = `ls -sl`;
  218.     string $animCurveType = "animCurveTU";
  219.  
  220.     // clear textScrollList
  221.     textScrollList -e -ra "exportAttrList";
  222.  
  223.     for ($obj in $selList)
  224.     {
  225.     string $id = nodeType( $obj );
  226.     if ( strcmp( $id, $animCurveType ) == 0 )
  227.     {
  228.         textScrollList -e -a $obj exportAttrList;
  229.     }
  230.  
  231.     $conAttr = `listAttr -k $obj`;
  232.     for ($attr in $conAttr)
  233.     {
  234.         $objAttr = ($obj + "." + $attr);
  235.         $connected = `listConnections -d false $objAttr`;
  236.         if (size($connected)>0)
  237.         {
  238.         textScrollList -e -a $objAttr exportAttrList;
  239.         }
  240.     }
  241.     }    
  242.   
  243. }  // end updateSelected()
  244.  
  245.  
  246. proc makeAttrWin (string $win)
  247. {
  248.     // variable declaration for text fields
  249.     global string $name;
  250.  
  251.     window -title "Composer Curve Export Tool" 
  252.         -iconName "Composer Export"
  253.         $win;
  254.  
  255.     // set up text list for attributes
  256.     formLayout composerForm;
  257.  
  258.     text -al "left" -l "Selected Objects With Inputs" textPrompt;
  259.     textScrollList -w 325 -h 158 -nr 9 -ams true exportAttrList;
  260.  
  261.     // setup for text inputs
  262.  
  263.     $name = `textFieldGrp -cal 1 right -cw 1 50 -enable true -l "Name"
  264.         -tx "MayaCurve.cmp" `;
  265.  
  266.     float $s = `playbackOptions -q -min`;
  267.     float $e = `playbackOptions -q -max`;
  268.  
  269.     // setup for export and close buttons
  270.  
  271.     button -l "Export Selected"
  272.         -c ("getExportAttr" + " exportAttrList" + " 0;" + "window -e -vis 0 " + $win )
  273.         expSelButton;
  274.     button -l "Export All"
  275.         -c ("getExportAttr" + " exportAttrList" + " 1;" + "window -e -vis 0 " + $win )
  276.         expAllButton;
  277.     button -l "Cancel" -c ("window -e -vis 0 " + $win)
  278.         cancelButton;
  279.  
  280.     formLayout -edit
  281.         -af textPrompt "top" 5
  282.         -af textPrompt "left" 5
  283.         -af textPrompt "right" 5
  284.         
  285.         -ac exportAttrList "top" 2 textPrompt
  286.         -af exportAttrList "left" 5
  287.         -af exportAttrList "right" 5
  288.         -ac exportAttrList "bottom" 5 $name
  289.         
  290.         -af $name "left" 5
  291.         -af $name "right" 5
  292.         -ac $name "bottom" 5 expSelButton
  293.         
  294.         -an expSelButton "top" 
  295.         -af expSelButton "left" 5
  296.         -ap expSelButton "right" 2 33
  297.         -af expSelButton "bottom" 5
  298.         
  299.         -an expAllButton "top" 
  300.         -ap expAllButton "left" 2 33
  301.         -ap expAllButton "right" 2 66
  302.         -af expAllButton "bottom" 5
  303.         
  304.         -an cancelButton "top" 
  305.         -ap cancelButton "left" 2 66
  306.         -af cancelButton "right" 5
  307.         -af cancelButton "bottom" 5
  308.         
  309.         composerForm;
  310.  
  311.  
  312. }  // end makeAttrWin()
  313.  
  314.  
  315. global proc exportComposerCurves()
  316. {
  317.     global int $tvcExportWindow;
  318.     $win = "tvcCurveWin";
  319.     if (!`window -exists $win`)
  320.     {
  321.     makeAttrWin ($win);
  322.     $tvcExportWindow = `scriptJob -p $win -e "SelectionChanged"
  323.         updateSelected`;
  324.     updateSelected;
  325.     }
  326.     showWindow $win;
  327. }
  328.